package com.group.zsxm.web.action;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.apache.struts2.config.ParentPackage;
import org.apache.struts2.config.Result;
import org.apache.struts2.config.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.fins.gt.server.GridServerHandler;
import com.group.core.Constants;
import com.group.core.common.Page;
import com.group.zsxm.entity.DmMc;
import com.group.zsxm.entity.Xtuser;
import com.group.zsxm.service.DwsbService;
import com.group.zsxm.service.DwsbqueryService;
import com.group.zsxm.service.JfhsbqueryService;
import com.group.zsxm.web.common.BaseAction;
import com.opensymphony.xwork2.Action;
@ParentPackage("appDefault")
@Scope("prototype")
@Controller
@Results( { 
			@Result(name = "input", value = "/WEB-INF/jsp/query/dwsbquery.jsp"),
			@Result(name = "view1", value = "/WEB-INF/jsp/query/dwsb1view.jsp"),
			@Result(name = "view2", value = "/WEB-INF/jsp/query/dwsb2view.jsp"),
			@Result(name = "view3", value = "/WEB-INF/jsp/query/dwsb3view.jsp"),
			@Result(name = "q1", value = "/WEB-INF/jsp/query/dwsb1_q.jsp"),
			@Result(name = "q2", value = "/WEB-INF/jsp/query/dwsb2_q.jsp"),
			@Result(name = "q3", value = "/WEB-INF/jsp/query/dwsb3_q.jsp")
		})
public class DwsbqueryAction extends BaseAction{
	@Autowired
	@Qualifier("dwsbService")
	private DwsbService dwsbService;
	@Autowired
	@Qualifier("dwsbqueryService")
	private DwsbqueryService dwsbqueryService;
	private String opttype;
	private Map<String, String> dwsb;
	private List<Map<String, String>> lxs;
	private List<Map<String, String>> jbdms;
	private List<DmMc> jbdmlxs;
	private Map<String, String> jbxx;
	private String sbdm;
	private String jbdm;
	private String jbdmlx;
	private String xlxtype;
	private List<DmMc> xlxtypes;
	private Xtuser xtuser ;
	public Xtuser getXtuser() {
		return xtuser;
	}

	public void setXtuser(Xtuser xtuser) {
		this.xtuser = xtuser;
	}
	public void onPrepare() {
		xtuser = (Xtuser)getSession().getAttribute(Constants.USER_SESSION_KEY);
	}
	
	public String execute(){
		jbdms = dwsbService.getDwsbListByDwid(xtuser.getUserid());
		jbdmlxs = ArrayToList(new String[]{"1","2","3"}, new String[]{"常州市国家大学科技园在孵企业","常州市国家大学科技园研发机构","常州市国家大学科技园西区院校"});
		xlxtypes = ArrayToList(new String[]{"1","2"}, new String[]{"季报","机构性质"});
		return Action.INPUT;
	}
	
	public String query(){
		jbdms = dwsbService.getDwsbListByDwid(xtuser.getUserid());
		jbdmlxs = ArrayToList(new String[]{"1","2","3"}, new String[]{"常州市国家大学科技园在孵企业","常州市国家大学科技园研发机构","常州市国家大学科技园西区院校"});
		xlxtypes = ArrayToList(new String[]{"1","2"}, new String[]{"季报","机构性质"});
		if(xlxtype.equals("1")){
			Integer dwlx = dwsbqueryService.getDwsbLx(jbdm, xtuser.getUserid());
			return "q"+dwlx;
		}else{
			return "q"+jbdmlx;
		}
	}
	
	public void getList() {
		GridServerHandler gridHandler = new GridServerHandler(getRequest(), getResponse());
		getLimitPage().setRowAttributes(gridHandler.getTotalRowNum(), gridHandler.getPageNum(), gridHandler.getPageSize());
		Map param = getParameterSimpleMap();
		Page page = (Page) dwsbqueryService.getDwsbList(getLimitPage(), param, gridHandler.getSingleSortInfo(), gridHandler.getFilterInfo(),xtuser.getUserid());
		gridHandler.setTotalRowNum(page.getTotalCount());
		gridHandler.setData((List) page.getData());
		renderText(gridHandler.getLoadResponseText());
	}

	public void exportList() {
		GridServerHandler gridHandler = new GridServerHandler(getRequest(), getResponse());
		Map param = getParameterSimpleMap();
		List list = (List) dwsbqueryService.getDwsbList(null, param, gridHandler.getSingleSortInfo(), gridHandler.getFilterInfo(),xtuser.getUserid());
		try {
			gridHandler.exportXLSfromMaps(list);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}


	public String dwsb1view(){
		jbxx = dwsbService.getDwsbJbxx(xtuser.getUserid());
		lxs = dwsbService.getDwsblxList();
		dwsb = dwsbService.preDwsb1(xtuser.getUserid(), sbdm);
		return "view1";
	}
	public String dwsb2view(){
		jbxx = dwsbService.getDwsbJbxx(xtuser.getUserid());
		dwsb = dwsbService.preDwsb2(xtuser.getUserid(), sbdm);
		return "view2";
	}
	public String dwsb3view(){
		jbxx = dwsbService.getDwsbJbxx(xtuser.getUserid());
		dwsb = dwsbService.preDwsb3(xtuser.getUserid(), sbdm);
		return "view3";
	}
	
	
	/**
	 * Mapping
	 * @return
	 */
	public String getOpttype() {
		return opttype;
	}

	public void setOpttype(String opttype) {
		this.opttype = opttype;
	}

	public DwsbqueryService getDwsbqueryService() {
		return dwsbqueryService;
	}

	public void setDwsbqueryService(DwsbqueryService dwsbqueryService) {
		this.dwsbqueryService = dwsbqueryService;
	}

	public DwsbService getDwsbService() {
		return dwsbService;
	}

	public void setDwsbService(DwsbService dwsbService) {
		this.dwsbService = dwsbService;
	}

	public List<Map<String, String>> getLxs() {
		return lxs;
	}

	public void setLxs(List<Map<String, String>> lxs) {
		this.lxs = lxs;
	}

	public List<Map<String, String>> getJbdms() {
		return jbdms;
	}

	public void setJbdms(List<Map<String, String>> jbdms) {
		this.jbdms = jbdms;
	}

	public String getJbdm() {
		return jbdm;
	}

	public void setJbdm(String jbdm) {
		this.jbdm = jbdm;
	}

	public List<DmMc> getJbdmlxs() {
		return jbdmlxs;
	}

	public void setJbdmlxs(List<DmMc> jbdmlxs) {
		this.jbdmlxs = jbdmlxs;
	}

	public String getJbdmlx() {
		return jbdmlx;
	}

	public void setJbdmlx(String jbdmlx) {
		this.jbdmlx = jbdmlx;
	}

	public String getXlxtype() {
		return xlxtype;
	}

	public void setXlxtype(String xlxtype) {
		this.xlxtype = xlxtype;
	}

	public List<DmMc> getXlxtypes() {
		return xlxtypes;
	}

	public void setXlxtypes(List<DmMc> xlxtypes) {
		this.xlxtypes = xlxtypes;
	}

	public Map<String, String> getDwsb() {
		return dwsb;
	}

	public void setDwsb(Map<String, String> dwsb) {
		this.dwsb = dwsb;
	}

	public String getSbdm() {
		return sbdm;
	}

	public void setSbdm(String sbdm) {
		this.sbdm = sbdm;
	}

	public Map<String, String> getJbxx() {
		return jbxx;
	}

	public void setJbxx(Map<String, String> jbxx) {
		this.jbxx = jbxx;
	}



}
